/**
 * Copyright (c) 2017 ucsmy.com, All rights reserved.
 */
package itsm.isperp.module.controller.api.wechat.v2;

import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.change.ChgChange;
import itsm.isperp.module.entity.configuration.ConfCi;
import itsm.isperp.module.entity.project.ProjProject;
import itsm.isperp.module.service.change.ChgChangeService;
import itsm.isperp.module.service.configuration.ConfCiService;
import itsm.isperp.workflow.dto.BpmTransitionLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: legen
 * @Created Date: 2017-11-07-0007.
 * @LastModifyDate: 2017-11-07-0007.
 * @LastModifyBy: legen
 * @Version:
 */
@Controller
@RequestMapping("api/wechat/v2/equipment")
public class EquipmentController extends BaseController {

    @Autowired
    private ConfCiService confCiService;

    @Autowired
    private ChgChangeService chgChangeServie;

    @RequestMapping("query")
    @ResponseBody
    public List<Map<String, Object>> query(String username, String keyword) {
        JqGridRequest request = new JqGridRequest();
        request.setPageable(false);
        request.setSelectColumns("id", "name", "code", "conf_category_name", "status");
        request.setSort("code", Sort.Direction.ASC);
        request.setSearchString("a.name like '%" + keyword + "%' or a.code like '%" + keyword + "%' or a.conf_category_name like '%" + keyword + "%'");

        return confCiService.findAllDetailByRequest(request);
    }

    /**
     * 设备明细
     */
    @RequestMapping("detail")
    @ResponseBody
    public ConfCi detail(String username, String id)
            throws Exception {
        JqGridRequest request = new JqGridRequest();
        request.addFilterRule("id", JqGridFilterRuleOp.eq, id);
        ConfCi data = confCiService.findOneByRequest(request);

        if (data != null) {
            return data;
        } else {
            throw new Exception("该设备已删除!");
        }
    }

    @RequestMapping("failureResume")
    @ResponseBody
    public List<Map<String, Object>> failureResume(String username, String id) {
        List<Map<String, Object>> list = confCiService.findCiIncidentDetail(id);
        return list;
    }

    @RequestMapping("changeResume")
    @ResponseBody
    public List<Map<String, Object>> changeResume(String username, String id) {
        List<Map<String, Object>> list = chgChangeServie.findCiChangeDetail(id);
        return list;
    }
}
